package str;

import java.util.Arrays;

/**
 * @Author: Darven
 * @CreateTime: 2025-04-03  23:27
 * @Description: TODO
 */
public class P560 {
    public static void main(String[] args) {
        P560Demo p560Demo = new P560Demo();
        System.out.println(p560Demo.subarraySum(new int[]{-1,-1,1}, 0));
    }
}

class P560Demo{
    public int subarraySum(int[] nums, int k) {
        int ans=0;
        int left=0;
        int n=0;
        for(int i=0;i<nums.length;i++){
            n+=nums[i];
            if(n==k||nums[i]==k){
                ans++;
            }

            if(n>=k){
                n-=nums[left];
                left++;
            }
        }
        return ans;
    }
}
